<script setup lang="ts">
//
import { storeToRefs } from 'pinia'
import { reactive, computed, watch } from 'vue'
import BarOrLine from '@/components/Echart/Bar/BarOrLine.vue'
import { useFinanceStore } from '@/stores/module/finance'
import { useDialogStore } from '@/stores/dialog'
const dialogStore = useDialogStore()
const { dialogInfo } = dialogStore
const dialogInfoVisible = dialogInfo.visible
const financeStore = useFinanceStore() // 创建store实例
const { getFixedExpenses }: any = storeToRefs(financeStore)

const options = computed(() => {
  return {
    name: 'FixedExpenses',
    subTitle: getFixedExpenses.value.headline,
    subTitleVal: getFixedExpenses.value.totalSum,
    xAxis: {
      type: 'category',
      data: getFixedExpenses.value.sub_titles,
    },
    data: getFixedExpenses.value.info,
  }
})
watch(
  () => getFixedExpenses.value,
  () => {
    // options.value.subTitle = getFixedExpenses.headline
    options.value.data.splice(
      0,
      options.value.data.length,
      ...getFixedExpenses.value.info
    )
    options.value.xAxis.data.splice(
      0,
      options.value.xAxis.data.length,
      ...getFixedExpenses.value.sub_titles
    )
  },

  { deep: true }
)
</script>
<template>
  <card-box componentName="FixedExpenses">
    <template v-slot:title v-if="getFixedExpenses.title">
      <h1
        :class="{
          subtitle: dialogInfoVisible,
        }"
      >
        {{ getFixedExpenses.title }}
      </h1>
    </template>
    <!-- <div class="sub-title">
        {{ getFixedExpenses.headline }}
        <span>{{ getFixedExpenses.totalSum }}</span>
      </div> -->
    <BarOrLine :chart-data="options" v-if="getFixedExpenses.info.length" />
    <div v-else class="default-img">
      <p>{{ $t('bi_common_nodata') }}</p>
    </div>
  </card-box>
</template>
<style lang="scss" scoped>
.default-img {
  width: 100%;
  text-align: center;
  padding: 120px 0;
  background-image: url('@/assets/images/canvsimage/default.png');
  background-repeat: no-repeat;
  background-position: center;

  font-size: 16px;
  color: #00f6ff;
}
// .sub-title {
//   padding: 10px;
//   font-size: 12px;
//   span {
//     color: #eb6456;
//   }
// }
.subtitle {
  font-size: 30px;
}
</style>
